package com.viroyal.monitorlib.network.socket;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * Created by cxy on 2016/9/18.
 */
public class DeviceIdEncoder extends MessageToByteEncoder<ByteBuf> {
    private String mDevId = "";

    public DeviceIdEncoder() {

    }

    public void setDevId(String id) {
        mDevId = id;
    }

    public String getDevId() {
        return mDevId;
    }

    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, ByteBuf msg, ByteBuf out) throws Exception {
        out.writeBytes(mDevId.getBytes());
        out.writeBytes(msg, msg.readerIndex(), msg.readableBytes());
    }

    @Override
    public boolean isSharable() {
        return true;
    }
}
